<!DOCTYPE html>
<html lang="en" xmlns:th="http://wwww.thymeleaf.org">
<head>
    <meta name="renderer" content="webkit">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <!--<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">-->
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <base href="<%=url%>">
    <title></title>
    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>

    <link type="text/css" th:href="@{/css/cure.css}" rel="stylesheet">
    <script th:src="@{https://lib.baomitu.com/jquery/3.4.1/jquery.min.js}"></script>
    <script th:src="@{https://lib.baomitu.com/layui/2.6.5/layui.min.js}"></script>
    <link th:href="@{https://lib.baomitu.com/layui/2.6.5/css/layui.min.css}" rel="stylesheet">

    <!--避开thymeleaf的影响，单独访问时调用js css -->
    <link type="text/css" href="/css/cure.css" rel="stylesheet">
    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://lib.baomitu.com/layui/2.6.5/layui.min.js"></script>
    <link href="https://lib.baomitu.com/layui/2.6.5/css/layui.min.css" rel="stylesheet">
    <!--<link type="text/css" href="/css/cure.css" rel="stylesheet">-->
</head>

<body>
<div class="conter">
           <!--支付层-->
    <div id="abb-layer" style="display: none; padding: 20px">
        <form id="abb-form" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">充值卡号</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="CZvisid" class="layui-input" lay-verify="required" readonly="readonly">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">充值金额</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="CZmoney" class="layui-input" lay-verify="required" >
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" class="layui-btn" id="CZbut" value="确认充值">

                </div>
            </div>
        </form>
    </div>



    <!-- 体检办理弹出层 -->
    <div id="add-layer" style="display: none;padding: 20px;height: 400px">
        <form id="add-form" class="layui-form layui-form-pane">

            <div class="layui-form-item">
                <label class="layui-form-label">患者卡号</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="vvisid" class="layui-input" lay-verify="required" readonly="readonly">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">患者姓名</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="uname" id="uuname" class="layui-input" lay-verify="required"
                               autocomplete="off" readonly="readonly">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">办理医生</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="did" id="ddid" class="layui-input" lay-verify="required"
                               readonly="readonly">
                    </label>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">科室</label>
                <div class="layui-input-block">
                    <label>

                        <input type="text" name="phone" class="layui-input" value="体检科" lay-verify="required"
                               readonly="readonly">
                    </label>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">体检医生</label>
                <div class="layui-input-block">
                    <label>
                        <!--<select class="aaa layui-input search_input">-->
                        <!--</select> 活得乳酸菌-->
                        <input type="text" name="phone" class="layui-input" value="王二生" lay-verify="required"
                               readonly="readonly">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="notes" class="layui-input" lay-verify="required">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" class="layui-btn" id="tjyubut" value="办理体检">
                    <!--<button class="layui-btn" id="tjyubut"  lay-filter="add-form-submit">添加</button>-->
                    <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                </div>
            </div>
        </form>
    </div>
    <!--住院-->
    <div id="zuyuan-layer" style="display: none; padding: 20px">
        <form id="zhuyuan-form" class="layui-form layui-form-pane">

            <div class="layui-form-item">
                <label class="layui-form-label">患者卡号</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="uvisid" class="layui-input" readonly lay-verify="required">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">患者姓名</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="unamee" class="layui-input" readonly lay-verify="required"
                               autocomplete="off">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">办理医生</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="didname" class="layui-input" lay-verify="required" autocomplete="off">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">住院区域</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="zfqy" class="layui-input" lay-verify="required" autocomplete="off">
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" id="note" class="layui-input" lay-verify="required" autocomplete="off">
                    </label>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="text-align: center">
                    <input type="button" value="提交" id="zybut" class="layui-btn">
                </div>
            </div>
        </form>
    </div>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-md6">

                <div id="handy-left">
                    <div id="handy-01">
                        <br>
                        <span style="font-size: 40px;font-weight:bold;"> 新乡第一人民医院</span><br/><br>
                        <span style="font-size: 25px;">普通电子处方单 </span>
                        <br>
                        <br/>
                        <input id="yydid" th:value="${dbs.id}" hidden>
                        处方号<input type="text" th:value="${dbs.id}+${dbs.visid}" id="ydbh" style="width: 140px"
                                  readonly="readonly">
                        <input id="ksid" th:value="${dbs.ksid}" hidden>
                        科室<input type="text" th:value="${dbs.ksname}" id="department" style="width: 91px"
                                 readonly="readonly">
                        预约日期<input type="text" th:value="${#dates.format(dbs.visitdate, 'yyyy-MM-dd')}" id="createDate"
                                   style="width: 133px" readonly="readonly">
                        <br> <br>
                        卡号<input type="text" th:value="${dbs.visid}" style="width: 91px" readonly="readonly" id="visid">
                        姓名<input type="text" id="uname" th:value="${dbs.uname}" style="width: 91px" readonly="readonly">
                        性别<input type="text" id="sex" th:value="${dbs.sex}" style="width: 75px" readonly="readonly">
                        年龄<input type="text" id="age"
                                 th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy')}-${#dates.format(dbs.birthday, 'yyyy')}"
                                 style="width:75px" readonly="readonly">
                        <br> <br>
                        <!--<span style="color: red">* 该医院单次门诊收费为</span><span ><b style="font-size: 20px">50</b>元</span>-->
                        <br>
                        <hr style="margin-right: 50px;margin-left: 50px;">
                    </div>
                    <div id="tbody">
                        <span style="float: left;font-size: 65px;margin-left: 100px;">R</span>
                        <span style="float: left;font-size: 80px;">p</span>
                        <span style="float: left;font-size: 80px;margin-top: 22px;">:</span>
                        <br><br><br><br><br><br><br><br>
                        <div id="tbody01">
                        </div>
                    </div>
                    <hr style="margin-right: 20px;margin-left: 20px;">
                    <div id="tfoot">
                        <input id="diid" th:value="${dbs.did}" hidden>
                        <div id="tfoot_one"><span style="float: left">主治医生<input id="did" type="text"
                                                                                 th:value="${dbs.name}"
                                                                                 style="width: 91px"
                                                                                 readonly="readonly"></span> <span
                                style="float: right;margin-right: 20px;">就诊时间:<input type="text"
                                                                                     th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}"
                                                                                     style="width: 91px;border: 0px"
                                                                                     readonly="readonly"></span></span>
                        </div>
                        <br> <br><br>
                        <div style="text-align: center;color: red;">*注：本处方为临床初步诊断</div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6">
                <div id="handy-right">
                    <div id="right_top">
                        <div id="handy-right_tilite" style="font-size: 30px;font-weight:bold;">体检信息</div>
                        <hr style="margin-right: 20px;margin-left: 20px;">
                        <div id="handy-right_body">
                            体检单号<input id="tjid" type="text" style="width: 178px" readonly="readonly">
                            体检时间<input id="edate" type="text" style="width: 178px" readonly="readonly">
                            <br/><br>
                            体温<input id="eschedule" type="text" style="width: 125px" readonly="readonly">
                            心率 <input id="eheartrate" type="text" style="width: 125px" readonly="readonly">
                            血压<input id="blood" type="text" style="width: 125px" readonly="readonly">
                            <br><br>
                            血尿常规<input id="urine" type="text" style="width: 178px" readonly="readonly">
                            肝肾功能<input id="function" type="text" style="width: 178px" readonly="readonly">
                            <br><br>
                            <button class="layui-btn layui-btn-sm" id="tjbut">查询体检信息</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <button class="layui-btn layui-btn-sm" id="bltj">办理体检</button>
                        </div>
                    </div>
                    <div id="right_center">

                        <div id="right_center_left">
                            <div class="center_top">患者描述</div>
                            <hr style="margin-left: 20px;margin-right: 20px;">
                            <div class="center_left">
                                <div class="cl_size">病情表述</div>
                                <div><textarea id="bqms"
                                               style="margin-left: 10px;width: 150px;height: 150px;resize: none"></textarea>
                                </div>
                            </div>
                            <div class="center_right">
                                <div>
                                    <div class="cl_size">个人史:</div>
                                    <textarea id="grs"
                                              style="margin-right: 15px;width: 160px;height: 60px;resize: none"></textarea>
                                </div>
                                <div>
                                    <div class="cl_size">家族史:</div>
                                    <textarea id="jzs"
                                              style="margin-right: 15px;width: 160px;height: 60px;resize: none"></textarea>
                                </div>
                            </div>
                        </div>

                        <div id="right_center_right">
                            <div class="center_top">医生诊断</div>
                            <hr style="margin-left: 20px;margin-right: 20px;">
                            <div><textarea id="yszd"
                                           style="width: 86%;height: 175px;margin-left: 20px;resize: none"></textarea>
                            </div>
                        </div>


                    </div>

                    <div id="right_foot">
                        <div id="foot_left">
                            <div class="center_top">处方药</div>
                            <hr style="margin-left: 20px;margin-right: 20px;">
                            <!--<div>-->
                            <!--药品名称: &nbsp;<input type="text" style="height:25px;width: 141px;border: 1px solid black;"/>-->
                            <!--<button>搜索</button>-->
                            <!--</div>-->
                            <br><br>
                            <div>
                                药房<select id="yfAll" style="width: 133px;height: 30px">
                            </select>
                                药品<select id="ypAll" style="width: 125px;height: 30px">
                            </select>
                                <br><br>
                                药品规格<input id="ypgg" type="text" style="width: 90px" readonly="readonly">
                                数量:<input id="ypnum" type="text" style="width: 42px"
                                          th:onkeyup="value=value.replace(/[^\d]/g,'')">
                                <input id="unit" type="text" style="width: 13px;border: 0px" readonly="readonly">
                                <br><br>
                                服用方法<select style="width: 60px" id="take1">
                                <option value="口服">口服</option>
                                <option value="外用">外用</option>
                            </select>&nbsp;&nbsp;&nbsp;&nbsp;
                                <select style="width: 83px" id="take2">
                                    <option value="一天一次">一天一次</option>
                                    <option value="一天两次">一天两次</option>
                                    <option value="一天三次">一天三次</option>
                                </select>
                                一次：<input type="text" style="width: 58px" id="take3">
                                <br><br>
                                <button id="qkyd" class="layui-btn layui-btn-sm layui-btn-danger" style="float: left;margin-left: 20px;">清空药单</button>
                                <button id="onege" class="layui-btn layui-btn-sm layui-btn-danger" style="float: left;margin-left: 20px;">清除上一条</button>
                                <button id="yptj" class="layui-btn layui-btn-sm"  style="float: right;margin-right: 40px;">添加药品</button>
                            </div>
                        </div>
                        <div id="foot_right">
                            <div class="cl_size">医嘱:</div>
                            <textarea id="yz" style="width: 100%;height: 70%;resize: none"></textarea>
                            <br><br>
                            <div>
                                <button style="float: left;margin-left: 15px;" class="layui-btn layui-btn-sm" id="zhuyuan">办理住院</button>
                                <button id="over" class="layui-btn layui-btn-sm" style="float: right;margin-right: 25px;">门诊结束</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

</body>
</html>
<script>

    //药房查询
    $(function () {
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中.............');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }
        $.get("/regist/dispensaryAll", function (date) {
            console.log(date)
            $("#ypAll").empty();
            if (date !== null) {
                $("#yfAll").append("<option value=" + 0 + " disabled=\"disabled\" selected=\"selected\">请选择要选择的药房</option>")
                for (var i = 0; i < date.length; i++) {
                    var option = "<option value=" + date[i].yfid + ">" + date[i].yfname + "</option>";
                    $("#yfAll").append(option);
                }
            } else {
                layer.open({
                    title: '提示'
                    , content: '暂时没有药房可选择！'
                    , icon: 2
                })
            }
        })
    })
    //药品查询添加//
    $("#yfAll").change(function () {
        var yfid = $("#yfAll").val();
        console.log(yfid + "<>")
        $.get("/regist/checkSerById", {yfid: yfid}, function (date) {
            console.log(date)
            $("#ypAll").empty();
            if (date !== null) {
                $("#ypAll").append("<option value=" + 0 + " disabled=\"disabled\" selected=\"selected\">请选择要选择的药品</option>")
                for (var i = 0; i < date.length; i++) {
                    $("#ypAll").append("<option value=" + date[i].ypid + ">" + date[i].ypname + "</option>")
                }
            } else if (date.length < 0) {
                layer.open({
                    title: '提示'
                    , content: '该药房暂时无药！'
                    , icon: 1
                })
            }
        })
    })
    //规格
    $("#ypAll").change(function () {
        var ypid = $("#ypAll").val();
        $.get("/regist/checkById", {ypid: ypid}, function (date) {
            $("#ypgg").val(date.normsid);
            $("#unit").val(date.unitname);
        })
    })
    var i = 1;
    var ary = [];
    $("#yptj").click(function () {
        var yydid = $("#yydid").val();//预约编号
        var did = $("#did").val();//医生
        var visid = $("#visid").val();//卡号
        var ydbh = $("#ydbh").val();//处方单编号
        var ypname = $("#ypAll option:selected");
        var ypid = $("#ypAll").val(); //药品id
        var ypgg = $("#ypgg").val(); //药品规格
        var ypnum = $("#ypnum").val(); //药品数量
        var nuit = $("#unit").val();
        var take1 = $("#take1").val(); //服用方式
        var take2 = $("#take2").val();
        var take3 = $("#take3").val();

        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中..........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1200)
            });
            return false;
        }


        if (ypname.text() == null || ypname.text() === '') {
            layer.open({
                title: '提示'
                , content: '请先选择药品！！'
                , icon: 2
            })
            return false;
        }

        if (ypnum == null || ypnum === '') {
            layer.open({
                title: '提示'
                , content: '请先填写药品数量！'
                , icon: 2
            })
            return false;
        }
        if (ypnum > 5) {
            layer.open({
                title: '提示'
                , content: '单次选择药品数量最大为5！'
                , icon: 2
            })
            return false;
        }
        if (ypnum <= 0) {
            layer.open({
                title: '提示'
                , content: '请规范填写药品数量'
                , icon: 2
            })
            return false;
        }
        if (take3 == null || take3 === '') {
            layer.open({
                title: '提示'
                , content: '请先填写服用剂量！'
                , icon: 2
            })
            return false;
        }
        $.get("/prescrip/ypinsert", {
            ydbh: ydbh,
            visid: visid,
            ypid: ypid,
            ypnum: ypnum,
            take: take1 + take2 + "每次" + take3,
            did: did
        }, function (data) {
            if (data == true) {
                var ypidd;
                var ydbhh;
                var ypnumm;
                for (var j in ary) {
                    ypidd = ary[j].ypid;
                    ydbhh = ary[j].ydbh;
                    ypnumm = ary[j].ypnum;
                }
                console.log(ypidd+"ypidd")
                console.log(ypid+"ypid")
                console.log(ypnumm+"ypnumm")
                console.log(ypnum+"ypnum")
         if(ypid==ypidd){
             ypnum = Number(ypnumm)+Number(ypnum);
        console.log(ypnum+"最后的数量")
             var vbs = document.getElementById("tbody01").getElementsByTagName("div");
             $("#tbody01 div:last-child").remove();
             ary.pop();
             i = i - 1;
             var data = '<div ><li>' + i + '<span id="a" style="margin-left:100px;margin-right: 20px">'
                 + ypname.text() + '</span><span> ' + "*" + ypnum + " " + nuit + '</span></li><span style="margin: 10px 0 10px 5px;">用法：<sapn>'
                 + take1 + '</sapn><sapn  style="margin-left:40px">' + take2
                 + '</sapn><sapn  style="margin-left:60px">' + "一次" + take3 + '</sapn></span><br/></div>'
             $("#tbody01").append(data)
             i++;
             layer.msg('添加成功');
             //添加数组
             var a = {
                 ydbh: ydbh,
                 visid: visid,
                 ypid: ypid,
                 ypgg: ypgg,
                 ypnum: ypnum,
                 take: take1 + "#" + take2 + "#每次" + take3,
                 did: did
             };
             ary.push(a);
         }else {
             var data = '<div ><li>' + i + '<span id="a" style="margin-left:100px;margin-right: 20px">'
                 + ypname.text() + '</span><span> ' + "*" + ypnum + " " + nuit + '</span></li><span style="margin: 10px 0 10px 5px;">用法：<sapn>'
                 + take1 + '</sapn><sapn  style="margin-left:40px">' + take2
                 + '</sapn><sapn  style="margin-left:60px">' + "一次" + take3 + '</sapn></span><br/></div>'
             $("#tbody01").append(data)
             i++;
             layer.msg('添加成功');
             //添加数组
             var a = {
                 ydbh: ydbh,
                 visid: visid,
                 ypid: ypid,
                 ypgg: ypgg,
                 ypnum: ypnum,
                 take: take1 + "#" + take2 + "#每次" + take3,
                 did: did
             };
             ary.push(a);

         }
      } else {
                layer.msg('库存数量不足,无法继续添加');
            }
        })
    })

    $("#qkyd").click(function () {
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中..........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }


        if (ary == null || ary.length <= 0) {
            layer.msg('尚未添加是药品');
            return false;
        }
        layer.confirm('确定要清除所有药品吗？', function (index) {
            var ydbh;
            for (var j in ary) {
                ydbh = ary[j].ydbh
            }
            $.get("/prescrip/deldiaid", {ydbh: ydbh}, function (data) {
                if (data == true) {
                    layer.msg('清除成功');
                    $("#tbody01").empty();
                    ary = [];
                    layer.msg('清除成功');
                    i = 1;
                } else {
                    layer.msg('清除失败');
                }
            })

            layer.close(index);
        })
    })

    $("#onege").click(function () {
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中...........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }


        if (ary == null || ary.length <= 0) {
            layer.msg('尚未添加是药品');
            return false;
        }
        layer.confirm('确定去除上一条药品数据吗？', function (index) {
            var ypid;
            var ydbh;
            var ypnum;
            for (var j in ary) {
                ypid = ary[j].ypid;
                ydbh = ary[j].ydbh;
                ypnum = ary[j].ypnum;
            }
            $.get("/prescrip/minusNum", {ydbh: ydbh, ypid: ypid, ypnum: ypnum}, function (data) {
                if (data == true) {
                    layer.msg('移除成功');
                    var vbs = document.getElementById("tbody01").getElementsByTagName("div");
                    $("#tbody01 div:last-child").remove();
                    ary.pop();
                    i = i - 1;
                } else {
                    layer.msg('移除失败');
                }
            })
            layer.close(index);
        })
    })
</script>
<script>
    // <!--体检医生查询 活得乳酸菌-->
    // function ttjDocuser() {
    //     $.get("/appoint/seAll", function (date) {
    //         console.log(date)
    //         $(".aaa").empty();
    //         $(".aaa").append("<option value=" + 0 + " disabled=\"disabled\" selected=\"selected\">选择体检医生</option>");
    //         for (var i = 0; i < date.length; i++) {
    //             var option = "<option value=" + date[i].did + ">" + date[i].name + "</option>";
    //             $(".aaa").append(option);
    //             layui.form.render('select');
    //         }
    //     })
    // }


    var AddIndex;

    var visid = $("#visid").val()
    var uaname = $("#uname").val()
    var did = $("#did").val()

    $("#tjbut").click(function () {
        var yydid = $("#yydid").val();
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中..........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }

        $.ajax({
            url: "/appoint/tjcx",
            type: "get",
            contentType: "application/json",
            dataType: "json",
            data: {yydid: yydid, visid: visid},
            success: function (data) {
                if (data == 0) {
                    layer.open({
                        title: '提示'
                        , content: '该患者尚未办理体检'
                        , icon: 2
                    })
                    return false;
                } else if (data == 1) {
                    layer.open({
                        title: '提示'
                        , content: '该患者还未进行体检'
                        , icon: 1
                    })
                    return false;
                } else {
                    $("#tjid").val(data.id);
                    $("#edate").val(myDateFomat1(data.edate));
                    $("#function").val(data.function);
                    $("#urine").val(data.urine);
                    $("#blood").val(data.eblood);
                    $("#eschedule").val(data.eschedule);
                    $("#eheartrate").val(data.eheartrate);
                    return false;
                }
            }
        })
    })

    $('#bltj').click(function () {
        var yydid = $("#yydid").val();
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中.........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }

        $.ajax({
            url: "/appoint/tjcx",
            type: "get",
            contentType: "application/json",
            dataType: "json",
            data: {yydid: yydid, visid: visid},
            success: function (data) {
           if(data==0){
                   $("#vvisid").val(visid);
                   $("#uuname").val(uaname);
                   $("#ddid").val(did);
                   AddIndex = layer.open({
                       type: 1,
                       title: '办理体检',
                       skin: 'layui-layer-molv',
                       area: ['500px'],
                       content: $('#add-layer'),
                   });
                   ttjDocuser()
           }else if(data==1){
               //判断
                   layer.open({
                       title: '提示'
                       , content: '该患者已有预约'
                       , icon: 2
                   })
                   return false;
           }else {
               layer.open({
                   title: '提示'
                   , content: '该患者已体检'
                   , icon: 2
               })
               return false;
           }
            }
        })
    });

    var index1;
    var usefor1="门诊充值";
    $("#tjyubut").click(function () {
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中.........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }
        var yydid = $("#yydid").val();
        var tiprice=30; //体检费用
        var usefor="体检费用";
     ////////////////////////////////////////////////////////////////////////////////////////////
        layer.confirm("体检费用为" + "<span  style='color:red'>" + tiprice + "</span>" + "元将会从卡中余额扣除", function () {
            $.get("/diagnose/Mzprice", {visid: visid, price: tiprice,usefor:usefor}, function (data) {
    if(data==true){
        $.ajax({
            url: "/appoint/appinsert",
            type: "get",
            contentType: "application/json",
            // dataType:"json",
            data: {
                yydid: yydid,
                visid: $("#vvisid").val(),
                ksid: "7",
                did: "10009",
                // did: $(".aaa").val(), 活得乳酸菌
                state: "0",
                notes: $("#notes").val()
            },
            success: function (data) {
                if (data == true) {
                    layer.open({
                        title: '提示'
                        , content: '办理成功'
                        , icon: 1
                    });
                    layer.close(AddIndex);
                    return false;
                } else {
                    layer.open({
                        title: '提示'
                        , content: '办理失败'
                        , icon: 2
                    })
                    return false;

                }
            }
        })

    }else {
        layer.confirm("余额不足，是否进行缴费",function () {
            index1= layer.open({
                type: 1,
                title: usefor1,
                skin: 'layui-layer-molv',
                area: ['500px'],
                content: $('#abb-layer')
            });
           $("#CZvisid").val(visid);
        })
        return false;
    }
            })
        })
        return false;
    })

   $("#CZbut").click(function () {
       var CZvisid=$("#CZvisid").val();
       var CZmoney=$("#CZmoney").val();
      $.get("/diagnose/Mztopup",{CZvisid:CZvisid,CZmoney:CZmoney,usefor:usefor1},function (data) {
          if(data==true){
              layer.open({
                  title: '提示'
                  , content: '充值成功'
                  , icon: 1
              });
              layer.close(index1);
              return false;
          }else {
              layer.open({
                  title: '错误提示'
                  , content: '充值失败'
                  , icon: 2
              })

              return false;
          }
      })
   })



</script>
<script>

    var bfquid;
    var openzf;
    // 显示添加弹出层
    $('#zhuyuan').click(function () {
        var visid = $("#visid").val();
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中..........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }

        var tjid = $("#tjid").val();
        if (tjid == "" || tjid == null) {
            layer.open({
                title: '错误提示'
                , content: '该患者尚未体检,请先体检在判断是否住院'
                , icon: 2
            });
            return false;
        }
//病情表述
        var bqms = $("#bqms").val();
        if (bqms == "" || bqms == null) {
            layer.open({
                title: '错误提示'
                , content: '未填写病情表述，请先填写'
                , icon: 2
            });
            return false;
        }
//医生诊断
        var yszd = $("#yszd").val();
        if (yszd == "" || yszd == null) {
            layer.open({
                title: '错误提示'
                , content: '未填写医生诊断，请先填写'
                , icon: 2
            });
            return false;
        }


        openzf = layer.open({
            type: 1,
            title: '办理住院',
            skin: 'layui-layer-molv',
            area: ['500px'],
            content: $('#zuyuan-layer')
        });
        var ksid = $("#ksid").val();//科室id
        var uname = $("#uname").val();//患者姓名
        var visid = $("#visid").val();//患者卡号
        var did = $("#did").val();//医生姓名
        var uvisid = $("#uvisid").val(visid);
        var unamee = $("#unamee").val(uname);
        var didname = $("#didname").val(did);
        $.get("/sickroom/queryById", {ksid: ksid}, function (data) {
            $("#zfqy").val(data.name);
            bfquid = data.bfqyid;
        })
    });

    //添加住院申请
    $("#zybut").click(function () {
        var visid = $("#visid").val();//患者卡号
        var diid = $("#diid").val();//医生id
        var note = $("#note").val();//备注
        var yydid = $("#yydid").val();//预约编号
        var ydbh = $("#ydbh").val();//处方单编号
        var tjid = $("#tjid").val();//体检单号
        var bqms = $("#bqms").val();//病情描述
        var grs = $("#grs").val();//个人史
        var jzs = $("#jzs").val();//家族史
        var yszd = $("#yszd").val();//医生诊断
        var yz = $("#yz").val();//医嘱
        var price = 30;
        var usefor="门诊支付";
        layer.confirm("本次门诊收费" + "<span  style='color:red'>" + price + "</span>" + "元是否从卡中余额扣除", function () {
            $.get("/diagnose/Mzprice", {visid: visid, price: price,usefor:usefor}, function (data) {
                if(data==true){
                    $.get("/wardregist/wardinsert", {
                        diid: diid,
                        bfqyid: bfquid,
                        note: note,
                        yydid: yydid,
                        ydbh: ydbh,
                        visid: visid,
                        tjid: tjid,
                        bqms: bqms,
                        grs: grs,
                        jzs: jzs,
                        yszd: yszd,
                        yz: yz
                    }, function (data) {
                        if (data == true) {
                            layer.msg('住院办理成功');
                            layer.close(openzf);
                            if (ary == null || ary == "") {
                              layer.confirm('本次门诊结束<br/>,请告知患者寻找护士办理住院<br/>即将返回预约列表',function () {
                                  setTimeout(function () {
                                      window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                                  }, 1500)
                              })
                                // layer.msg('本次门诊结束,即将返回预约列表');
                                // setTimeout(function () {
                                //     window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                                // }, 2500)
                            } else {
                                layer.confirm("本次门诊结束" + "<br/>" + "请让患者记住<span style='color: red;font-size: 30px'><b>" + ydbh + "</b></span>它是患者取药的唯一凭证" + "<br/>" + "点击确认后自动跳转页面",function () {
                                        window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                                })
                            }

                        } else {
                            layer.msg('办理失败');
                        }
                    })

                }else {

                    layer.confirm("患者卡中余额不足，是否进行缴费",function () {
                        index1= layer.open({
                            type: 1,
                            title: usefor1,
                            skin: 'layui-layer-molv',
                            area: ['500px'],
                            content: $('#abb-layer')
                        });
                        $("#CZvisid").val(visid);
                    })
                    return false;

                }
            })})



    })


</script>
<script>
    $("#over").click(function () {
        var yydid = $("#yydid").val();//预约编号
        var ydbh = $("#ydbh").val();//处方单编号
        var visid = $("#visid").val()//卡号
        var tjid = $("#tjid").val();//体检单号
        var did = $("#diid").val();//医生id
        var bqms = $("#bqms").val();//病情描述
        var grs = $("#grs").val();//个人史
        var jzs = $("#jzs").val();//家族史
        var yszd = $("#yszd").val();//医生诊断
        var yz = $("#yz").val();//医嘱
        var price = 30;
        var usefor="门诊支付";
        if (visid == "" || visid == null) {
            layer.confirm('您尚未选着患者，是否选择患者进行诊治？', function (index) {
                layer.msg('页面跳转中..........');
                setTimeout(function () {
                    window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                }, 1500)
            });
            return false;
        }


        if (bqms == "" || bqms == null) {
            layer.open({
                title: '错误提示'
                , content: '病情描述不能为空'
                , icon: 2
            })
            return false;
        }
        if (yszd == "" || yszd == null) {
            layer.open({
                title: '错误提示'
                , content: '医生诊断尚未填写'
                , icon: 2
            })
            return false;
        }
        if (yz == "" || yz == null) {
            layer.open({
                title: '错误提示'
                , content: '医嘱不能为空'
                , icon: 2
            })
            return false;
        }

        layer.confirm("本次门诊收费" + "<span  style='color:red'>" + price + "</span>" + "元是否从卡中余额扣除", function () {
            $.get("/diagnose/Mzprice", {visid: visid, price: price,usefor:usefor}, function (data) {
                if (data == true) {
                    $.get("/diagnose/insert",
                        {
                            yydid: yydid,
                            ydbh: ydbh,
                            visid: visid,
                            tjid: tjid,
                            did: did,
                            bqms: bqms,
                            grs: grs,
                            jzs: jzs,
                            yszd: yszd,
                            yz: yz
                        }
                        , function (data) {
                            if (data == true) {
                           if(ary==null|| ary==""){
                              layer.confirm("门诊结束" + "<br/>" + "已从患者卡中扣除门诊费用" + "<span  style='color:red'>" + price + "</span>" + "元" + "<br/>" + "点击确认后页面将会自动跳转",function () {
                                  window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                              })
                               // layer.open({
                               //     title: '注意'
                               //     , content: "门诊结束" + "<br/>" + "已从患者卡中扣除门诊费用" + "<span  style='color:red'>" + price + "</span>" + "元" + "<br/>" + "页面等待跳转中.........."
                               //     , icon: 1
                               // })
                               // setTimeout(function () {
                               //     window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                               // },5000)
                               return false;
                           }else{
                               layer.confirm("门诊结束" + "<br/>" + "已从患者卡中扣除门诊费用" + "<span  style='color:red'>" + price + "</span>" + "元" + "<br/>" + "请让患者记住<span style='color: red;font-size: 30px'><b>" + ydbh + "</b></span>它是患者取药的唯一凭证" + "<br/>" + "点击确认后页面将会自动跳转", function () {
                                   window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                               })
                               // layer.open({
                               //     title: '注意'
                               //     , content: "门诊结束" + "<br/>" + "已从患者卡中扣除门诊费用" + "<span  style='color:red'>" + price + "</span>" + "元" + "<br/>" + "请让患者记住<span style='color: red;font-size: 30px'><b>" + ydbh + "</b></span>它是患者取药的唯一凭证" + "<br/>" + "页面等待跳转中"
                               //     , icon: 1
                               // })
                               // setTimeout(function () {
                               //     window.location.href = "http://localhost:8080/ManagementEnd/Home/pick_patient.html";
                               // },5000)
                               return false;
                           }
                            } else {
                                layer.msg('数据异常请重试');
                            }
                        })
                }
                else {
                    layer.confirm("余额不足，是否进行缴费",function () {
                        index1= layer.open({
                            type: 1,
                            title: usefor1,
                            skin: 'layui-layer-molv',
                            area: ['500px'],
                            content: $('#abb-layer')
                        });
                        $("#CZvisid").val(visid);
                    })
                    return false;
                }
            })
        })
    })
</script>
<script>
    function myDateFomat1(t) {
        var date = new Date(t);
        var y = date.getFullYear();
        var m = (date.getMonth() + 1).toString().padStart(2, "0");
        var d = (date.getDate()).toString().padStart(2, "0");
        return y + "-" + m + "-" + d;
    }

    function myDateFomat2(t) {
        var date = new Date(t);
        var y = date.getFullYear();
        var m = (date.getMonth() + 1).toString().padStart(2, "0");
        var d = date.getDate().toString().padStart(2, "0");
        var h = date.getHours().toString().padStart(2, "0");
        var f = date.getMinutes().toString().padStart(2, "0");
        var s = date.getSeconds().toString().padStart(2, "0");
        return y + "-" + m + "-" + d + " " + h + ":" + f + ":" + s;
    }
</script>